package com.wg.dao;

import org.springframework.jdbc.core.JdbcTemplate;

public class JdbcUtils {
    //新版本使用Spring管理的druid连接池来使用
        private JdbcTemplate jdbcTemplate;
        public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
                this.jdbcTemplate = jdbcTemplate;
        }
        public JdbcTemplate getJdbc(){
            return jdbcTemplate;
        }

        //老版本使用配置文件来连接
    /*public static Connection getConnection(){
            //数据库的连接属性放在硬盘上的jdbc.properties, url username password从这里读取
            //获得连接
            Connection connection = null;
            try {
                    InputStream inputStream = JdbcUtils.class.getClassLoader().getResourceAsStream("jdbc.properties");
                    //获得配置文件
                    Properties properties = new Properties();
                    properties.load(inputStream);
                    String driver = properties.getProperty("driver");
                    //加载驱动
                    Class.forName(driver);
                    String url = properties.getProperty("url");
                    String name = properties.getProperty("username");
                    String password = properties.getProperty("password");
                    connection = DriverManager.getConnection(url, name, password);
            } catch (IOException e) {
                    e.printStackTrace();
            } catch (ClassNotFoundException e) {
                    e.printStackTrace();
            } catch (SQLException throwables) {
                    throwables.printStackTrace();
            }
            return connection;
    }*/
}
